package java_thinking.unit_11._11_11;

import java.util.*;

/**
 * @Description : 具有优先顺序的queue
 * @author: cww
 * @DateTime: 2019-03-18 22:04
 */

public class PriorityQueueDemo {
    public static void main(String[] args) {
        PriorityQueue<Integer> pq = new PriorityQueue<>();
        Random random = new Random(47);
        for (int i =0;i<10;i++){
            pq.offer(random.nextInt(i+10));
        }
        QueueDemo.printQ(pq);
        //默认最小值有最高的出栈权限
        List<Integer> ints = Arrays.asList(25,22,20,18,14,9,3,1,1,2,3,9,14,18,21,23,25);
        pq = new PriorityQueue<>(ints);
        QueueDemo.printQ(pq);
        System.out.println();

        //Collections.<Integer>reverseOrder() 产生反序的Comparator
        pq = new PriorityQueue<>(ints.size(), Collections.<Integer>reverseOrder());
        pq.addAll(ints);
        QueueDemo.printQ(pq);
        System.out.println();

        String fact = "EDUCATION SHOULD ESCHEW OBFUSCATION";
        List<String> strings = Arrays.asList(fact.split(""));
        PriorityQueue<String> pqStr = new PriorityQueue<>(strings);
        pqStr.addAll(strings);
        QueueDemo.printQ(pqStr);
        System.out.println();

        Set<Character> charSet = new HashSet<>();
        for (char c:fact.toCharArray()){
            charSet.add(c);
        }
        PriorityQueue<Character> pqChar = new PriorityQueue<>(charSet);
        QueueDemo.printQ(pqChar);
    }
}
